package com.example.yunJie.digitalSentry.control;


import com.example.yunJie.digitalSentry.entity.MarketEntity;
import com.example.yunJie.digitalSentry.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Market")
public class MarketControl {
    @Autowired
    private MarketService marketService;

    @RequestMapping("/add")
    public void  insert(MarketEntity marketEntity){
        if (marketService.findIdByMarketName(marketEntity.getMarketName()) == null){
            marketService.insert(marketEntity);
        }

    }

    @RequestMapping("/update")
    public int update(MarketEntity marketEntity){
        return marketService.update(marketEntity);
    }

    @RequestMapping("/deleteById")
    public int  deleteById(int id){
        return marketService.deleteById(id);
    }

    @RequestMapping("/deleteIdList")
    public int  deleteIdList(List<Integer> id){
        return marketService.deleteIdList(id);
    }

    @RequestMapping("/findId")
    public MarketEntity  findId(String id){
        return marketService.findId(id);
    }

    @RequestMapping("/findAll")
    public List<MarketEntity>  findAll(){
        return marketService.findAll();
    }
}
